# -*- coding: utf-8 -*- 
from calculator import Calculator
from utility import distanceByPixel

def get_pairs(n):
    r = []
    l = range(n)
    for i in l[:-1]:
        index = l.index(i)
        for j in l[index + 1:]:
            r.append((i,j))
    return r
            
        
class Calculator_all_dots(Calculator):
    
    def prepare_raw_data(self):
        ds = self.dots.get_dots()
        n = len(ds)
        pairs = get_pairs(n)
        
        head = []; r = []
        
        for p in pairs:
            
            s = "%s--%s"%(str(p[0]+1),str(p[1]+1))
            head.append(s) 
            
            a, b = ds[p[0]],ds[p[1]]
            d = distanceByPixel(a,b)
            r.append(d)
            
        self.result.append([head,])
        self.result.append(r)
        
    def prepare_title(self):
        self.title += "所有点间的距离"
            
            
        